<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>libxlsxwriter: conditional_format1.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">libxlsxwriter
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">conditional_format1.c</div>  </div>
</div><!--header-->
<div class="contents">
<table width="600">
<tr>
<td><a class="el" href="data_validate_8c-example.html">&lt;&lt; data_validate.c</a> </td><td align="right"><a class="el" href="conditional_format2_8c-example.html">conditional_format2.c &gt;&gt;</a>  </td></tr>
</table>
<p>A simple example of how to add a conditional format a libxlsxwriter file. Conditional formatting allows you to apply a format to a cell or a range of cells based on certain criteria.</p>
<div class="image">
<img src="conditional_format12.png" alt=""/>
</div>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * An a simple example of how to add conditional formatting to an</span></div>
<div class="line"><span class="comment"> * libxlsxwriter file.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * See conditional_format.c for a more comprehensive example.</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> * Copyright 2014-2020, John McNamara, jmcnamara@cpan.org</span></div>
<div class="line"><span class="comment"> *</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;xlsxwriter.h&quot;</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> </div>
<div class="line">    <a name="_a0"></a><a class="code" href="structlxw__workbook.html">lxw_workbook</a>  *workbook  = <a name="a1"></a><a class="code" href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a>(<span class="stringliteral">&quot;conditional_format_simple.xlsx&quot;</span>);</div>
<div class="line">    <a name="_a2"></a><a class="code" href="structlxw__worksheet.html">lxw_worksheet</a> *worksheet = <a name="a3"></a><a class="code" href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a>(workbook, NULL);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Write some sample data. */</span></div>
<div class="line">    <a name="a4"></a><a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a name="a5"></a><a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B1&quot;</span>), 34, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B2&quot;</span>), 32, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B3&quot;</span>), 31, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B4&quot;</span>), 35, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B5&quot;</span>), 36, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B6&quot;</span>), 30, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B7&quot;</span>), 38, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B8&quot;</span>), 38, NULL);</div>
<div class="line">    <a class="code" href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a>(worksheet, <a class="code" href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a>(<span class="stringliteral">&quot;B9&quot;</span>), 32, NULL);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Add a format with red text. */</span></div>
<div class="line">    <a name="_a6"></a><a class="code" href="structlxw__format.html">lxw_format</a> *custom_format = <a name="a7"></a><a class="code" href="workbook_8h.html#a279a5d7075d09a3931aae9782afede33">workbook_add_format</a>(workbook);</div>
<div class="line">    <a name="a8"></a><a class="code" href="format_8h.html#a61981b2080bfe6381ede5358ee05b05c">format_set_font_color</a>(custom_format, <a name="a9"></a><a class="code" href="format_8h.html#abeafc6e8222ba9fcfd4f2c2f4e9ea38baedd7412491d9f34fc5f947ada9d196ec">LXW_COLOR_RED</a>);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Create a conditional format object. A static object would also work. */</span></div>
<div class="line">    <a name="_a10"></a><a class="code" href="structlxw__conditional__format.html">lxw_conditional_format</a> *conditional_format = calloc(1, <span class="keyword">sizeof</span>(<a class="code" href="structlxw__conditional__format.html">lxw_conditional_format</a>));</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Set the format type: a cell conditional: */</span></div>
<div class="line">    conditional_format-&gt;<a name="a11"></a><a class="code" href="structlxw__conditional__format.html#ad184e6a2d11120c042c22e181b15a348">type</a>     = <a name="a12"></a><a class="code" href="worksheet_8h.html#affdc3f401f3ee241fad5d651628ac92dac9180feb375f5d9302d80467398a0c6e">LXW_CONDITIONAL_TYPE_CELL</a>;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Set the criteria to use: */</span></div>
<div class="line">    conditional_format-&gt;<a name="a13"></a><a class="code" href="structlxw__conditional__format.html#a06fc7b5549574bac769cf93ae7180e3f">criteria</a> = <a name="a14"></a><a class="code" href="worksheet_8h.html#a47b554f3a8f1475b57df705fd326ae6bae8a15acdb209feb53b8948c0e50cc9c3">LXW_CONDITIONAL_CRITERIA_LESS_THAN</a>;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Set the value to which the criteria will be applied: */</span></div>
<div class="line">    conditional_format-&gt;<a name="a15"></a><a class="code" href="structlxw__conditional__format.html#aa11acc4f64d532fafc7cda9a98dc1fc9">value</a>    = 33;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Set the format to use if the criteria/value applies: */</span></div>
<div class="line">    conditional_format-&gt;<a name="a16"></a><a class="code" href="structlxw__conditional__format.html#a3d3ca3432272ee4d5172349ae030dfcc">format</a>   = custom_format;</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Now apply the format to data range. */</span></div>
<div class="line">    <a name="a17"></a><a class="code" href="worksheet_8h.html#aef79f21eefbda49cd04e338d958c8a95">worksheet_conditional_format_range</a>(worksheet, <a name="a18"></a><a class="code" href="utility_8h.html#a4dbbdfc9b616195c799dee78e727cecc">RANGE</a>(<span class="stringliteral">&quot;B1:B9&quot;</span>), conditional_format);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">/* Free the object and close the file. */</span></div>
<div class="line">    free(conditional_format);</div>
<div class="line">    <span class="keywordflow">return</span> <a name="a19"></a><a class="code" href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a>(workbook);</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
<div class="ttc" id="aworkbook_8h_html_ad9e7aeebc0fd43562db5bcd527b2ee5e"><div class="ttname"><a href="workbook_8h.html#ad9e7aeebc0fd43562db5bcd527b2ee5e">workbook_close</a></div><div class="ttdeci">lxw_error workbook_close(lxw_workbook *workbook)</div><div class="ttdoc">Close the Workbook object and write the XLSX file.</div></div>
<div class="ttc" id="astructlxw__conditional__format_html"><div class="ttname"><a href="structlxw__conditional__format.html">lxw_conditional_format</a></div><div class="ttdoc">Worksheet conditional formatting options.</div><div class="ttdef"><b>Definition:</b> worksheet.h:998</div></div>
<div class="ttc" id="astructlxw__conditional__format_html_a3d3ca3432272ee4d5172349ae030dfcc"><div class="ttname"><a href="structlxw__conditional__format.html#a3d3ca3432272ee4d5172349ae030dfcc">lxw_conditional_format::format</a></div><div class="ttdeci">lxw_format * format</div><div class="ttdef"><b>Definition:</b> worksheet.h:1034</div></div>
<div class="ttc" id="aworkbook_8h_html_a1cf96608a23ee4eb0e8467c15240d00b"><div class="ttname"><a href="workbook_8h.html#a1cf96608a23ee4eb0e8467c15240d00b">workbook_new</a></div><div class="ttdeci">lxw_workbook * workbook_new(const char *filename)</div><div class="ttdoc">Create a new workbook object.</div></div>
<div class="ttc" id="astructlxw__conditional__format_html_ad184e6a2d11120c042c22e181b15a348"><div class="ttname"><a href="structlxw__conditional__format.html#ad184e6a2d11120c042c22e181b15a348">lxw_conditional_format::type</a></div><div class="ttdeci">uint8_t type</div><div class="ttdef"><b>Definition:</b> worksheet.h:1003</div></div>
<div class="ttc" id="astructlxw__worksheet_html"><div class="ttname"><a href="structlxw__worksheet.html">lxw_worksheet</a></div><div class="ttdoc">Struct to represent an Excel worksheet.</div><div class="ttdef"><b>Definition:</b> worksheet.h:1603</div></div>
<div class="ttc" id="astructlxw__format_html"><div class="ttname"><a href="structlxw__format.html">lxw_format</a></div><div class="ttdoc">Struct to represent the formatting properties of an Excel format.</div><div class="ttdef"><b>Definition:</b> format.h:358</div></div>
<div class="ttc" id="autility_8h_html_a4dbbdfc9b616195c799dee78e727cecc"><div class="ttname"><a href="utility_8h.html#a4dbbdfc9b616195c799dee78e727cecc">RANGE</a></div><div class="ttdeci">#define RANGE(range)</div><div class="ttdoc">Convert an Excel A1:B2 range into a (first_row, first_col, last_row, last_col) sequence.</div><div class="ttdef"><b>Definition:</b> utility.h:82</div></div>
<div class="ttc" id="aworksheet_8h_html_affdc3f401f3ee241fad5d651628ac92dac9180feb375f5d9302d80467398a0c6e"><div class="ttname"><a href="worksheet_8h.html#affdc3f401f3ee241fad5d651628ac92dac9180feb375f5d9302d80467398a0c6e">LXW_CONDITIONAL_TYPE_CELL</a></div><div class="ttdeci">@ LXW_CONDITIONAL_TYPE_CELL</div><div class="ttdef"><b>Definition:</b> worksheet.h:231</div></div>
<div class="ttc" id="astructlxw__workbook_html"><div class="ttname"><a href="structlxw__workbook.html">lxw_workbook</a></div><div class="ttdoc">Struct to represent an Excel workbook.</div><div class="ttdef"><b>Definition:</b> workbook.h:273</div></div>
<div class="ttc" id="astructlxw__conditional__format_html_a06fc7b5549574bac769cf93ae7180e3f"><div class="ttname"><a href="structlxw__conditional__format.html#a06fc7b5549574bac769cf93ae7180e3f">lxw_conditional_format::criteria</a></div><div class="ttdeci">uint8_t criteria</div><div class="ttdef"><b>Definition:</b> worksheet.h:1011</div></div>
<div class="ttc" id="aformat_8h_html_abeafc6e8222ba9fcfd4f2c2f4e9ea38baedd7412491d9f34fc5f947ada9d196ec"><div class="ttname"><a href="format_8h.html#abeafc6e8222ba9fcfd4f2c2f4e9ea38baedd7412491d9f34fc5f947ada9d196ec">LXW_COLOR_RED</a></div><div class="ttdeci">@ LXW_COLOR_RED</div><div class="ttdef"><b>Definition:</b> format.h:217</div></div>
<div class="ttc" id="astructlxw__conditional__format_html_aa11acc4f64d532fafc7cda9a98dc1fc9"><div class="ttname"><a href="structlxw__conditional__format.html#aa11acc4f64d532fafc7cda9a98dc1fc9">lxw_conditional_format::value</a></div><div class="ttdeci">double value</div><div class="ttdef"><b>Definition:</b> worksheet.h:1015</div></div>
<div class="ttc" id="aworksheet_8h_html_ad9fc47d3beaa2ab4759414e8580c2289"><div class="ttname"><a href="worksheet_8h.html#ad9fc47d3beaa2ab4759414e8580c2289">worksheet_write_number</a></div><div class="ttdeci">lxw_error worksheet_write_number(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, double number, lxw_format *format)</div><div class="ttdoc">Write a number to a worksheet cell.</div></div>
<div class="ttc" id="aformat_8h_html_a61981b2080bfe6381ede5358ee05b05c"><div class="ttname"><a href="format_8h.html#a61981b2080bfe6381ede5358ee05b05c">format_set_font_color</a></div><div class="ttdeci">void format_set_font_color(lxw_format *format, lxw_color_t color)</div><div class="ttdoc">Set the color of the font used in the cell.</div></div>
<div class="ttc" id="aworksheet_8h_html_a47b554f3a8f1475b57df705fd326ae6bae8a15acdb209feb53b8948c0e50cc9c3"><div class="ttname"><a href="worksheet_8h.html#a47b554f3a8f1475b57df705fd326ae6bae8a15acdb209feb53b8948c0e50cc9c3">LXW_CONDITIONAL_CRITERIA_LESS_THAN</a></div><div class="ttdeci">@ LXW_CONDITIONAL_CRITERIA_LESS_THAN</div><div class="ttdef"><b>Definition:</b> worksheet.h:311</div></div>
<div class="ttc" id="aworksheet_8h_html_aef79f21eefbda49cd04e338d958c8a95"><div class="ttname"><a href="worksheet_8h.html#aef79f21eefbda49cd04e338d958c8a95">worksheet_conditional_format_range</a></div><div class="ttdeci">lxw_error worksheet_conditional_format_range(lxw_worksheet *worksheet, lxw_row_t first_row, lxw_col_t first_col, lxw_row_t last_row, lxw_col_t last_col, lxw_conditional_format *conditional_format)</div><div class="ttdoc">Add a conditional format to a worksheet range.</div></div>
<div class="ttc" id="autility_8h_html_ad510ac6df573d23203374e24dba373d2"><div class="ttname"><a href="utility_8h.html#ad510ac6df573d23203374e24dba373d2">CELL</a></div><div class="ttdeci">#define CELL(cell)</div><div class="ttdoc">Convert an Excel A1 cell string into a (row, col) pair.</div><div class="ttdef"><b>Definition:</b> utility.h:45</div></div>
<div class="ttc" id="aworkbook_8h_html_a81d456b4f65a464e78e4a0030ecc3c2e"><div class="ttname"><a href="workbook_8h.html#a81d456b4f65a464e78e4a0030ecc3c2e">workbook_add_worksheet</a></div><div class="ttdeci">lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)</div><div class="ttdoc">Add a new worksheet to a workbook.</div></div>
<div class="ttc" id="aworkbook_8h_html_a279a5d7075d09a3931aae9782afede33"><div class="ttname"><a href="workbook_8h.html#a279a5d7075d09a3931aae9782afede33">workbook_add_format</a></div><div class="ttdeci">lxw_format * workbook_add_format(lxw_workbook *workbook)</div><div class="ttdoc">Create a new Format object to formats cells in worksheets.</div></div>
<!-- HTML footer for doxygen 1.8.20-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Copyright 2014-2020 John McNamara.
Generated by&#160;<a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20
</small></address>
</body>
</html>
